Fix constraints path to be relative to requirements file location#61
Merged
Fix constraints path to be relative to requirements file location#61
Conversation
Tests demonstrate that constraints path in requirements-out should be relative to the requirements file's directory, not from the config file location.
- processing.py: Calculate relative path from requirements-out directory to constraints-out file using os.path.relpath() - Handles different directory scenarios (same dir, parent dir, subdirs) - Falls back to absolute path if relpath fails (e.g., different drives on Windows) - CHANGES.md: Document the fix
c8bf5fe to
78df434
Compare
Move 'import os' to top of processing.py file for better code organization.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #22 and #25: Constraints file path in requirements-out is now correctly calculated as a relative path from the requirements file's directory.
Problem
When and are in different directories, the generated requirements file referenced constraints with the wrong path, causing pip to fail.
Example from #22:
Before (broken):
requirements/plone.txtcontained:Pip interprets
-cpaths relative to the requirements file's directory, so it looked for:After (fixed):
requirements/plone.txtnow contains:Because both files are in
requirements/, the relative path is justconstraints.txt.Solution
Added path calculation logic in src/mxdev/processing.py:
This works for all scenarios:
constraints.txt../constraints.txtsubdir/constraints.txt../other/constraints.txtChanges
os.path.relpath()Test Coverage
Both tests demonstrate the bug and verify the fix.
cc @davisagli @gforcada